<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
    <title>极目云医</title>
    <meta name="decorator" content="default"/>
</head>
<body>

<style>
    .parsley-errors-list{
        display: none;
    }
</style>

<div class="app" id="contentDiv">
    <section class="col-lg-12 panel" style="min-height:40%;border:1px solid:gray">
        <jsp:include page="prescProjectTop.jsp"></jsp:include>
    </section>
    <section class="col-lg-12 panel" style="height: 50%;">
        <div id="treatProjectItem">
            <jsp:include page="prescProjectItemBottom.jsp"></jsp:include>
        </div>
    </section>

</div>

<script>
    function addSubProjectDivN(tr, showDiv, url, itemClass, applyId) {
        $(tr).each(function (i, e) {
            $(this).parent().find("tr").removeClass("table-selected");
            $(this).addClass("table-selected");
//            }
        })
        loadDiv(showDiv, url);
    }

    function addTreat(visitId, clinicId, patientId, prescApplyId, inoroutFlag) {
        var selectedTr = $("#applyPrescTable .table-selected").find("td").eq(0).find("input").val();
        var itemClass = $("#applyPrescTable .table-selected").find("td").eq(7).find("input").val();
        if (itemClass == "A") {
            if (selectedTr == "undefined" || selectedTr == undefined) {
                toastr.info("请先选择一条模板，再插入！");
            } else {
                var trList = $("#itemTableList").find("tr");
                var list = "";
                var text = "";
                for (var i = 1; i < trList.length; i++) {
                    var tdArr = trList.eq(i).find("td");
                    var orderClass = tdArr.eq(1).find('input').val();//类别
                    var orderText = tdArr.eq(3).text()//处方名称
                    var performFreq = tdArr.eq(4).find('input').val();//频次
                    var administration = tdArr.eq(5).find('input').val();//途径
                    var singleDose = tdArr.eq(6).find('input').val();//单次用量
                    var singleDoseUnit = tdArr.eq(7).text();//单次用量单位
                    var packageSpec = tdArr.eq(8).text();//包装规格
                    var amount = tdArr.eq(9).find('input').val();//数量
                    var quantity = tdArr.eq(10).text();//数量
                    var price = tdArr.eq(11).text();//单价
                    var doctInstruction = tdArr.eq(12).text();//医生说明
                    var orderCode = tdArr.eq(13).find("input").eq(0).val();//医生说明
                    var firmId = tdArr.eq(13).find("input").eq(1).val();//厂家id
                    var firmName = tdArr.eq(13).find("input").eq(2).val();//厂家name
                    var newDept = tdArr.eq(13).find("input").eq(3).val();//开单科室
                    var isSkin = tdArr.eq(13).find("input").eq(4).val();//是否皮试
                    var applyId = tdArr.eq(13).find("input").eq(6).val();//主表id
                    var priceId = tdArr.eq(13).find("input").eq(7).val();//主表id
                    var parent = tdArr.eq(13).find("input").eq(8).val();//父级id
                    var packageUnits = tdArr.eq(13).find("input").eq(9).val();//包装单位
                    var spec = tdArr.eq(13).find("input").eq(10).val();//最小规格
                    var id = tdArr.eq(13).find("input").eq(11).val();//最小规格
                    if (quantity - amount <= 0) {
                        toastr.info("第" + i + "行：“" + orderText + "”此药库存不足，请调整开药数量");
//          break;
                        return false;
                    } else {
                        text += "<tr><td><input type='hidden' name='list[" + i + "].orderClass'" + " value='" + orderClass + "'/>" +
                        "<input type='hidden' name='list[" + i + "].drugName'" + " value='" + orderText + "'/>" +
                        "<input type='hidden' name='list[" + i + "].frequency'" + " value='" + performFreq + "'/>" +
                        "<input type='hidden' name='list[" + i + "].channel'" + " value='" + administration + "'/>" +
                        "<input type='hidden' name='list[" + i + "].singleDosage'" + " value='" + singleDose + "'/>" +
                        "<input type='hidden' name='list[" + i + "].singleUnit'" + " value='" + singleDoseUnit + "'/>" +
                        "<input type='hidden' name='list[" + i + "].packageSpec'" + " value='" + packageSpec + "'/>" +
                        "<input type='hidden' name='list[" + i + "].num'" + " value='" + amount + "'/>" +
                        "<input type='hidden' name='list[" + i + "].price'" + " value='" + price + "'/>" +
                        "<input type='hidden' name='list[" + i + "].doctInstruction'" + " value='" + doctInstruction + "'/>" +
                        "<input type='hidden' name='list[" + i + "].drugCode'" + " value='" + orderCode + "'/>" +
                        "<input type='hidden' name='list[" + i + "].firmId'" + " value='" + firmId + "'/>" +
                        "<input type='hidden' name='list[" + i + "].firmName'" + " value='" + firmName + "'/>" +
                        "<input type='hidden' name='list[" + i + "].newDept'" + " value='" + newDept + "'/>" +
                        "<input type='hidden' name='list[" + i + "].isSkin'" + " value='" + isSkin + "'/>" +
                        "<input type='hidden' name='list[" + i + "].applyId'" + " value='" + applyId + "'/>" +
                        "<input type='hidden' name='list[" + i + "].priceId'" + " value='" + priceId + "'/>" +
                        "<input type='hidden' name='list[" + i + "].parent.id'" + " value='" + parent + "'/>" +
                        "<input type='hidden' name='list[" + i + "].unit'" + " value='" + singleDoseUnit + "'/>" +
                        "<input type='hidden' name='list[" + i + "].packageUnit'" + " value='" + packageUnits + "'/>" +
                        "<input type='hidden' name='list[" + i + "].tempalteId'" + " value='" + id + "'/>" +
                        "<input type='hidden' name='list[" + i + "].spec'" + " value='" + spec + "'/>" +
                        "</td></tr>";
                    }
                }
                list = "<table>" + text + "</table>";
                $("#addForm").html(list);

                parentDivLoad('prescWesternItemDiv', 'addForm', '${ctx}/doctor/prescriptionItem/index?patientId=' + patientId + '&applyId=' + prescApplyId + '&clinicId=' + clinicId + '&inoroutFlag=' + inoroutFlag, '${ctx}/doctor/prescriptionItem/saveTreatTemplate?prescApplyId=' + prescApplyId + '&id=' + selectedTr + '&clinicId=' + clinicId + '&visitId=' + visitId + '&patientId=' + patientId);
            }
        } else {
            if ($('#prescChineseItemForm').parsley().validate()) {
                parentDivLoadItem('applyDiv','prescChineseItemDiv','prescChineseItemForm','${ctx}/doctor/prescriptionApply/applyIndex?clinicId=' + clinicId + '&patientId=' + patientId + '&visitId=' + visitId, '${ctx}/doctor/prescriptionItem/saveChinaTem?clinicId=' + clinicId + '&visitId=' + visitId + '&patientId=' + patientId+'&applyId=' + prescApplyId, '${ctx}/doctor/prescriptionItem/chineseIndex?applyId=' + prescApplyId);
            }
        }
    }



</script>
<script src="${ctxStatic}/js/template/template.js"></script>
</body>
</html>